var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2pvzChannel = require("pvzChannel");
var $2BundleManager = require("BundleManager");
var $2DataManager = require("DataManager");
var $2PlantMgr = require("PlantMgr");
var $2UIManager = require("UIManager");
var $2UserDataManager = require("UserDataManager");
var $2TaSdk = require("TaSdk");
var $2NoCoinUI = require("NoCoinUI");
var $2RewardUI = require("RewardUI");
var g = cc._decorator.ccclass;
var def_ShopItem = /* */function (_cc$Component65) {
  babel_inherits(p, _cc$Component65);
  var _super81 = babel_createSuper(p);
  function p() {
    babel_classCallCheck(this, p);
    return _super81.apply(this, arguments);
  }
  babel_createClass(p, [{
    key: "onLoad",
    value: function onLoad() {}
  }, {
    key: "init",
    value: function init(e, t) {
      this.id = t;
      this.shopItem = e;
      this.node.getChildByName("Plant").getChildByName("PlantIcon").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "PlantIcon/p_" + this.shopItem.id, cc.SpriteFrame);
      if ($2UserDataManager.default.instance.plantLock.includes(this.shopItem.id)) {
        this.node.getChildByName("Num").active = false;
        this.node.getChildByName("Label").active = true;
      } else {
        var _e100 = $2UserDataManager.default.instance.getPlantChip(this.shopItem.id);
        this.node.getChildByName("Num").getComponent(cc.RichText).string = _e100 >= 20 ? "(<color=#FFFFFF><outline color=black>".concat(_e100, "</outline></color>/20)") : "(<color=#FF0000><outline color=black>".concat(_e100, "</outline></color>/20)");
        this.node.getChildByName("Label").active = false;
        this.node.getChildByName("Num").active = true;
      }
      this.node.getChildByName("Desc").color = $2DataManager.default.instance.rareColor[this.shopItem.rare - 1];
      this.node.getChildByName("Cost").getChildByName("CostNum").getComponent(cc.Label).string = this.shopItem.cost;
      this.node.getChildByName("Plant").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ShopUI/s" + this.shopItem.rare, cc.SpriteFrame);
      if (1 == this.shopItem.discount) {
        this.node.getChildByName("Cost").getChildByName("DiscountNum").active = false;
        this.node.getChildByName("Cost").getChildByName("CostNum").getChildByName("line").active = false;
        this.node.getChildByName("discount").active = false;
        this.node.getChildByName("VideoBtn").active = false;
        this.node.getChildByName("BuyBtn").active = true;
      } else {
        if (0 == this.shopItem.discount) {
          this.node.getChildByName("VideoBtn").active = true, $2TaSdk.default.instance.AdsExposure($2TaSdk.VideoIndex.freeShop), this.node.getChildByName("BuyBtn").active = false, this.node.getChildByName("discount").active = false;
        } else {
          .5 == this.shopItem.discount ? this.node.getChildByName("discount").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ShopUI/discount5", cc.SpriteFrame) : this.node.getChildByName("discount").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ShopUI/discount8", cc.SpriteFrame), this.node.getChildByName("discount").active = true, this.node.getChildByName("VideoBtn").active = false, this.node.getChildByName("BuyBtn").active = true;
        }
        this.node.getChildByName("Cost").getChildByName("DiscountNum").active = true;
        this.node.getChildByName("Cost").getChildByName("CostNum").getChildByName("line").active = true;
        this.node.getChildByName("Cost").getChildByName("DiscountNum").getComponent(cc.Label).string = Math.floor(this.shopItem.cost * this.shopItem.discount) + "";
      }
      if ("a" == this.shopItem.type) {
        this.node.getChildByName("Plant").getChildByName("Chip").active = true;
        this.node.getChildByName("Plant").getChildByName("Num").active = true;
        this.node.getChildByName("Plant").getChildByName("Num").getComponent(cc.Label).string = "X" + this.shopItem.number;
        this.node.getChildByName("Desc").getComponent(cc.Label).string = $2PlantMgr.default.instance().getPlant(this.shopItem.id).name + "碎片";
      } else {
        this.node.getChildByName("Plant").getChildByName("Chip").active = false;
        this.node.getChildByName("Plant").getChildByName("Num").active = false;
        this.node.getChildByName("Desc").getComponent(cc.Label).string = $2PlantMgr.default.instance().getPlant(this.shopItem.id).name;
      }
      if ("g" == this.shopItem.costType) {
        this.node.getChildByName("Cost").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ui/a043", cc.SpriteFrame);
      } else {
        this.node.getChildByName("Cost").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ui/a042", cc.SpriteFrame);
      }
      if (this.shopItem.bought) {
        this.node.getChildByName("Mask").active = true;
        this.node.getChildByName("Label").active = false;
      } else {
        this.node.getChildByName("Mask").active = false;
      }
    }
  }, {
    key: "onClickBuyBtn",
    value: function onClickBuyBtn() {
      if ("g" == this.shopItem.costType) {
        if ($2UserDataManager.default.instance.gold < this.shopItem.cost * this.shopItem.discount) {
          return void $2UIManager.default.instance.openUI("NoCoinUI", 50).getComponent($2NoCoinUI.default).init(0);
        }
        $2UserDataManager.default.instance.gold -= this.shopItem.cost * this.shopItem.discount;
      } else {
        if ($2UserDataManager.default.instance.diamond < this.shopItem.cost * this.shopItem.discount) {
          return void $2UIManager.default.instance.openUI("NoCoinUI", 50).getComponent($2NoCoinUI.default).init(1);
        }
        this.shopItem.costType;
        $2UserDataManager.default.instance.diamond -= this.shopItem.cost * this.shopItem.discount;
      }
      this.getreward();
    }
  }, {
    key: "onClickVideoBtn",
    value: function onClickVideoBtn() {
      $2TaSdk.default.instance.AdsButtonClick($2TaSdk.VideoIndex.freeShop);
      var e = this;
      $2pvzChannel.pvzChannel.instance().showVideo({
        sucCall() {
          e.getreward();
        },
        failCall() {},
        endCall() {}
      });
    }
  }, {
    key: "getreward",
    value: function getreward() {
      if ("a" == this.shopItem.type) {
        $2UserDataManager.default.instance.setPlantChip(this.shopItem.id, this.shopItem.number);
      } else {
        $2UserDataManager.default.instance.getPlant(this.shopItem.id);
      }
      var e = [{
        rewardType: this.shopItem.type,
        rare: this.shopItem.rare,
        number: this.shopItem.number,
        plantID: this.shopItem.id
      }];
      this.shopItem.bought = true;
      this.init(this.shopItem, this.id);
      $2UIManager.default.instance.openUI("RewardUI", 30).getComponent($2RewardUI.default).init(e);
      $2UserDataManager.default.instance.changeshopInfo(this.id, this.shopItem);
    }
  }]);
  return p;
}(cc.Component);
def_ShopItem = cc__decorate([g], def_ShopItem);
exports.default = def_ShopItem;